<template>
  <div class="balance-log-con">
    <div class="table">
      <div class="thead">
        <div class="tr">
          <div class="td">收/支</div>
          <div class="td">余额</div>
          <div class="td">时间</div>
        </div>
      </div>
      <div class="tbody" v-show="balanceLog.length>0">
        <van-list
          v-model="loading"
          :finished="finished"
          :error.sync="error"
          error-text="请求失败，点击重新加载"
          finished-text=""
          @load="onLoad"
        >
          <div class="tr" v-for="(balanceItem,index) in balanceLog" :key="index">
            <div class="td">{{balanceItem.change_num}}</div>
            <div class="td">{{balanceItem.after_num}}</div>
            <div class="td">{{balanceItem.create_time}}</div>
          </div>
        </van-list>
      </div>
      <div class="tbody" v-show="!balanceLog.length && finished">
        <div class="tr">
          <div class="td no-data" style="width:100%;">暂无数据</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import noData from '@/components/noData/index'
import Vue from 'vue'
// import { Grid, GridItem } from 'vant'
// Vue.use(Grid).use(GridItem)
import { getAmountChangeList } from '@/api/user/gys/gysApi'

export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  props: {
    listPage: {
      type: Number,
      default: 0
    }
  },
  created() {
    this.init()
  },
  data() {
    return {
      noData: {
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无提现记录'
      },
      page: 1,
      balanceLog: [],
      error: false,
      loading: false,
      finished: false,
      isload: false
    }
  },
  watch: {
    'listPage': {
      handler(val) {
        if (val == 1) {
          this.page = 1
          this.isload = false
          this.finished = false
          this.onLoad()
        }
      },
      deep: true
    }
  },
  methods: {
    init() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)

      this.onLoad()
    },
    onLoad() {
      const params = {
        // act_type: false,
        p: this.page
      }
      if (this.isload && this.page == 1){
        this.finished = true
        return
      }
      if (this.finished) {
        return
      }
      getAmountChangeList(params)
        .then(res => {
          this.loading = false
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$emit('changeListPage', 0)
            const resData = res.data
            this.isload = true
            if (this.page == 1) {
              this.balanceLog = resData.data
            } else {
              this.balanceLog.push(...resData.data)
            }
            if (resData.data.length < 10) {
              this.finished = true
            } else {
              this.page++
            }
          } else {
            this.$Error(res.msg)
          }
        })
        .catch(() => {
          this.error = true
        })
      // const data = { p: this.p }
      // getLetter(data)
      //   .then(res => {
      //     this.loading = false
      //     this.$loadingWrap.close()
      //     if (res.status == 1) {
      //       this.lists.push(...res.data)
      //       this.p = this.p + 1
      //     } else {
      //       this.finished = true
      //     }
      //   })
      //   .catch(() => {
      //     this.error = true
      //   })
    }
  }
})
</script>

<style lang="scss">
.balance-log-con {
  // margin: 0 20px;
  text-align: center;
  .tr {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    border-bottom: 2px solid #ededed;
    &:last-child {
      border-bottom: 0;
    }
    .td {
      flex-basis: 33.3333%;
      flex-basis: 1;
      &:nth-child(1) {
        flex: 1;
      }
      &:nth-child(2) {
        flex: 1;
      }
      &:nth-child(3) {
        flex: 2;
      }
      &.no-data {
        color: #666;
      }
    }
  }
  .thead {
    background: #f7f7f7;
    line-height: 86px;
    .td {
      font-size: 24px;
      font-weight: bold;
      color: #333333;
    }
  }
  .tbody {
    .td {
      line-height: 100px;
      &:nth-child(1) {
        color: #fd2049;
        font-size: 28px;
        font-weight: bold;
      }
      &:nth-child(2) {
        color: #333;
        font-size: 28px;
        font-weight: bold;
      }
      &:nth-child(3) {
        font-size: 24px;
        color: #999;
      }
    }
  }
}
</style>
